package com.wangsb.code0401;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.UUID;

/**
 * @Description: TODO
 * @author: shenbing.wang@hand-china
 * @date: 2021年06月20日 14:58
 */
public class StudentSystem {


    public static void selectStus(List<Student> stus) {
        System.out.println("|学\t\t生\t\t信\t\t息\t\t表|");

        System.out.println("|学号|\t\t|姓名|\t\t|年龄|");
        if (stus != null) {
            for (Student student : stus) {
                System.out.println(student);
            }
        }

    }

    public static void insert(List<Student> stus) throws AgeAndStuNoException {
        selectStus(stus);
        Student student = new Student();
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入需要添加的学生姓名:");

        String name = scanner.next();
        student.setStuName(name);
        System.out.println("请输入需要添加的学生年龄:");
        int age = scanner.nextInt();
        student.setStuAge(age);
        System.out.println("请输入需要添加的学生学号:");
        String stuNo = scanner.next();
        student.setStuNo(stuNo);
        if (stus.size() < 1) {
            stus = new ArrayList<Student>();
        }
        stus.add(student);
        selectStus(stus);
    }

    public static void delete(List<Student> stus) {
        selectStus(stus);
        System.out.println("请选择您的要删除的学生学号:");
        Scanner scanner = new Scanner(System.in);
        String stuNo = scanner.next();

        Student delStu = null;
        for (Student student : stus) {
            if (stuNo.equals(student.getStuNo())) {
                delStu = student;
            }
        }
        if (delStu != null) {
            stus.remove(delStu);
        } else {
            System.out.println("请输入的学号不存在！");
        }
        selectStus(stus);
    }

    public static void update(List<Student> stus) throws AgeAndStuNoException {
        Scanner scanner = new Scanner(System.in);
        selectStus(stus);
        System.out.println("请选择您修改的学生学号:");
        String stuNo = scanner.next();

        Student updateStu = null;
        Student delStu = null;
        for (Student student : stus) {
            if (stuNo.equals(student.getStuNo())) {
                System.out.println("请输入需要添加的学生姓名:");
                String name = scanner.next();
                System.out.println("请输入需要添加的学生年龄:");
                int age = scanner.nextInt();
                delStu = student;
                updateStu = new Student(stuNo, name, age);

            } else {
                System.out.println("您输入的学号不存在！");
            }
        }
        if (delStu != null) {
            stus.remove(delStu);
            stus.add(updateStu);
        }
        selectStus(stus);

    }
}
